package com.ddfeiyu.client;

import io.netty.channel.Channel;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public abstract class MyBizHandler<T>  extends SimpleChannelInboundHandler<T>{
    private Logger logger = LoggerFactory.getLogger(MyBizHandler.class);

    @Override
    protected void channelRead0(ChannelHandlerContext ctx, T msg) throws Exception {
        channelRead(ctx.channel(), msg);
    }

    protected abstract void channelRead(Channel channel, T msg) throws Exception;


    @Override
    public void channelInactive(ChannelHandlerContext ctx) throws Exception {
        super.channelInactive(ctx);
        logger.warn("NettyClient断开连接了, channel:[ {} ]",ctx.channel().id());
    }

    @Override
    public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
        logger.error("NettyClient关闭 , channel:[ {} ]", ctx.channel().id());
    }
}
